package com.nf.xiaomi.web.controller;


import com.nf.mvc.ViewResult;
import com.nf.mvc.argument.RequestBody;
import com.nf.mvc.file.MultipartFile;
import com.nf.mvc.mapping.RequestMapping;
import com.nf.mvc.support.ResponseVO;
import com.nf.xiaomi.entity.ProductEntity;
import com.nf.xiaomi.service.ProductService;
import com.nf.xiaomi.service.impl.FileService;
import com.nf.xiaomi.service.impl.ProductServiceImpl;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import static com.nf.mvc.handler.HandlerHelper.json;

@RequestMapping("/product")

public class ProductController {
    ProductService service = new ProductServiceImpl();
    @RequestMapping("/typeAll")
    public ViewResult getTypeAll(String typeName){
        List<ProductEntity> typeAll = service.typeAll(typeName);
        return json(new ResponseVO(200, "ok", typeAll));
    }

    @RequestMapping("/getAll")
    public ViewResult getAll(){
        List<ProductEntity> all = service.getAll();
        return json(new ResponseVO(200, "ok", all));
    }

    @RequestMapping("/getAllName")
    public ViewResult getSearchAll(String name) {
        List<ProductEntity> products = service.getAll(name);
        return json(new ResponseVO(200, "ok", products));
    }

    @RequestMapping("/insert")
    public ViewResult insertProduct(ProductEntity productModel,@RequestBody MultipartFile[] files){
        ProductService service =new ProductServiceImpl();
        BigInteger productID = service.insert(productModel, files);
        return json(new ResponseVO(200,"ok",productID));
    }



}
